<template>
	<view>
		<view class="address-choose-box" v-if="JSON.stringify(address) == '{}'">
			<button type="primary" size="mini" class="btn-choose-address" @click="chooseAddress">请选择收货地址</button>
		</view>
		<view class="address-info" v-else @click="chooseAddress">
			<view class="address-info-top">
				<view class="address-person">
					<text>收货人：{{address.userName}}</text>
				</view>
				<view class="address-phone">
					<text>电话：{{address.telNumber}}</text>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<view class="address-info-bottom">
				<text>收货地址：{{addrStr}}</text>
			</view>
		</view>
		<!-- 底部的边框线 -->
		<image src="/static/cart_border@2x.png" class="address-border"></image>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations,
		mapState
	} from 'vuex'
	export default {
		name: "my-address",
		data() {
			return {};
		},
		computed: {
			...mapState('m_user', ['address']),
			...mapGetters('m_user', ['addrStr'])
		},
		methods: {
			...mapMutations('m_user', ['updateAddress']),
			async chooseAddress() {
				const [err, succ] = await uni.chooseAddress().catch(err => err);
				if (err == null && succ.errMsg == 'chooseAddress:ok') {
					console.log(succ)
					this.updateAddress(succ)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.address-info {
		font-size: 12px;
		height: 90px;
		padding: 0 5px;
		display: flex;
		flex-direction: column;
		justify-content: center;

		.address-info-top {
			display: flex;
			justify-content: space-between;

			.address-phone {
				margin-right: 5px;
			}
		}

		.address-info-bottom {
			margin-top: 10px;
		}
	}

	.address-choose-box {
		display: flex;
		justify-content: center;
		height: 90px;
		align-items: center;
	}

	.address-border {
		display: block;
		width: 100%;
		height: 5px;
	}
</style>
